export default class GUIManager { 
     public static subtitle(text: string){
        return new Promise<void>((resolve, reject) => {
            let box2 = UiBox.create()
            box2.name = "TempSubtitle"
            box2.parent = UiScreen.getAllScreen().find(obj => obj.name === 'screen')
            box2.position.scale.copy(Vec2.create({x: 0, y: 0.6}))
            box2.size.scale.copy(Vec2.create({x: 1, y:0.05}))
            box2.backgroundColor.copy(Vec3.create({r:31,g:64,b:255}))
            box2.backgroundOpacity = 0.5
            sleep(5000).then(() => {
                box2.parent = undefined
            })
        
            let textUI = UiText.create()
            textUI.visible = false
            textUI.name = "TempSubtitle"
            textUI.zIndex = 3
            textUI.parent = UiScreen.getAllScreen().find(obj => obj.name === 'screen')
            textUI.position.scale.copy(Vec2.create({x: 0.5, y: 0.7}))
            textUI.textFontSize = (screenWidth / screenHeight) * 25
        
            async function textFunc(){
                await sleep(1000)
                textUI.visible = true
                for(let i of text){
                    textUI.textContent += i 
                    await sleep(100)
                }
            }
        
            textFunc()
            
            sleep(5000).then(() => {
                textUI.parent = undefined
                resolve()
            })
            
        
            for(let i = 1; i > 0; i -= 0.0025){
                let box = UiBox.create()
                box.parent = UiScreen.getAllScreen().find(obj => obj.name === 'screen')
                box.size.scale.copy(Vec2.create({x: 1, y:0.01}))
                box.position.scale.copy(Vec2.create({x: 0, y: (i + 0.6)}))
                box.backgroundColor.copy(Vec3.create({r:42,g:108,b:248}))
                box.backgroundOpacity = i - Math.random() * 0.1
                box.name = "TempSubtitle"
                
        
                sleep(5000 + i * 300).then(() => {
                    box.parent = undefined
                })
            }
        })
        
    }
}